//
//  CZMainTarBarController.swift
//  weibotet
//
//  Created by admin on 16-2-25.
//  Copyright (c) 2016年 Wind. All rights reserved.
//

import UIKit

////1.设置代理方法
//@objc protocol CZMainTarBarControllerDelegate :NSObjectProtocol {
//    //按钮点击时调用
//       // optional表示代理方法是可选的
//    optional
//    //代理方法
//    func mainTabBarComposeClick()
//}

class CZMainTarBarController: UITabBar {
//    //2定义代理属性
//    weak var composeDelegate :CZMainTarBarController?
    
    //定义闭包
    var composeClosure : (() -> ())?
    
    
     override func layoutSubviews() {
        
     let width = frame.width/5
        composeButton.frame = CGRectMake(0, 0, width+5,frame.height )

        
   composeButton.center = CGPointMake(frame.width*0.5, frame.height*0.5)
    }
   
    
    

    //MARK: - 懒加载
    lazy var composeButton : UIButton = {
        
        let button = UIButton()
        
     
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named:"tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
    
        self.addSubview(button)
        
      button.sizeToFit()
        //添加点击事件
        button.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
        
    }()
    //点击事件
    func buttonClick () {
        composeClosure?()
    
    }
    
    
}
